package com.xxgc.quartzdemo.scheduler;

import com.xxgc.quartzdemo.job.ZhangSanJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ZhaoAnScheduler {
    @Bean
    public Scheduler zhaoAn() throws SchedulerException {
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();
        JobDetail build = JobBuilder.newJob(ZhangSanJob.class).build();
        scheduler.scheduleJob(build,cronTrigger);
        scheduler.start();
        return scheduler;
    }
}
